<template>
  <div>
    <el-form ref="loginForm" :rules="loginRules" :model="loginForm" class="login-form" status-icon label-width="0">
      <el-form-item prop="username">

        <div class="logininput">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-yonghu"></use>
          </svg>
          <el-input v-model="loginForm.username" size="small" auto-complete="off" placeholder="" @keyup.enter.native="handleLogin">
          </el-input>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="loginbtn sybtn" @click.native.prevent="handleLogin" :disabled="!(hdInfo.hdZt=='1')">确定<span v-if="!(hdInfo.hdZt=='1')">（测评{{hdInfo.hdZt == '1' ? '进行中' : '未知'}}）</span>
        </el-button>
      </el-form-item>
    </el-form>
    <ce-ping-pz ref="cePingpz" @next="reloadHd" />
  </div>

</template>

<script>
import { wdXuanPiaoXpNew } from "@/api/ceping/jxevalvote";
import cePingPz from '@/page/ceping/leaders/cpIndexpz4';
import { mapGetters } from "vuex";

export default {
  name: "Userlogin",
  components: {
    cePingPz,
  },
  data() {
    return {
      loginForm: {
        username: ""
      },
      checked: false,
      loginRules: {
        username: [
          { required: true, message: "请输入", trigger: "blur" },
        ]
      }
    };
  },
  props: {
    hdInfo: {
      default: {},
      type: Object
    }
  },
  computed: {
    ...mapGetters(["tagWel"])
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          let xpCode = this.loginForm.username + "";
          wdXuanPiaoXpNew(xpCode).then(res => {
            if (res.data.data.length > 0) {
              if (res.data.data[0].activityId == this.hdInfo.id) {
                this.$refs.cePingpz.initXp(xpCode);
                this.loginForm.username = "";
              } else {
                this.$notify.closeAll();
                this.$notify.error('该票号不在本次测评中');
              }
            } else {
              this.$notify.closeAll();
              this.$notify.error('票号中没有选票信息');
            }
          });
        }
      });
    },
    reloadHd() {

    },
  },
};
</script>

<style scoped>
.el-button--small {
  font-size: 30px !important;
}

</style>
